import React, { Component } from 'react';
import EChartReact from 'echarts-for-react';
import OptionFactory from '../charts/chartModel/optionFactory.js';

class VHChart extends Component {
	constructor(props){
		super(props);
		this.state = {
			option:{}
		}
	}
	static defaultProps = {		
		data:{},
		title:'',
		color:'',
		chartType:''
	}
	componentWillMount(){		
		if(this.props.data){
			let option = OptionFactory.createOption(this.props);
			this.setState({ option });
		}
	}
	componentWillReceiveProps(nextprops){
		if(nextprops.data){
			let option = OptionFactory.createOption(nextprops);
			this.setState({ option });
		}
	}
	render() {	
		// console.log('最终option', this.state.option)
	    return (
	       	<EChartReact  
				option={this.state.option} 
				className='echartReact'
		     />
	    );
	}
}

export default VHChart;
